package com.iran.composite.test;

import java.util.ArrayList;
import java.util.List;

public class ConcreteCompany extends Company {

    public ConcreteCompany(String name, Integer code) {
        super(name, code);
    }

    private List<Company> list = new ArrayList<>();


    @Override
    public void add(Company company) {
        list.add(company);
    }

    @Override
    public void del(Company company) {
        list.remove(company);
    }

    @Override
    public void display(int depth) {
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < depth; i++) {
            stringBuffer.append("-");
        }
        stringBuffer.append(getName());
        System.out.println(stringBuffer.toString());//打印这个公司的名称
        //遍历这个公司分支或叶子的名称
        list.forEach(company -> {
            company.display(depth+1);//+1代表子节点
        });
    }

    @Override
    public void lineDuty() {
        for (Company ea :list) {
            ea.lineDuty();
        }
    }
}
